package com.excerise.arr.hotel;

/**
 * 酒店对象
 *
 * @author Way on 2021/4/28
 */
@SuppressWarnings({"all"})
public class Hotel {

    private Room[][] rooms;

    /**
     * 初始化酒店
     */
    public Hotel() {
        // 3行10列，酒店总共三层，每层10个房间
        rooms = new Room[3][10];

        // 初始化
        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {
                // 房间号
                int roomNo = (i + 1) * 100 + (j + 1);
                // 房间类型：按楼层
                int roomType = Integer.parseInt(String.valueOf((i + 1)).substring(0, 1));
                rooms[i][j] = new Room(roomNo, roomType, false);
            }
        }
    }

    public void showRoomStatus() {
        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {
                System.out.println(rooms[i][j]);
            }
            System.out.println();
        }
    }

    /**
     * 预定房间
     */
    public void order(int roomNo) {
        Room room = commonService(roomNo);
        if (!check(room)) {
            System.out.println("房间号码有误，请重新输入！");
        } else if (room.isStatus()) {
            System.out.println("房间已预订，不可重复操作!");
        } else {
            room.setStatus(true);
            System.out.println("感谢您的操作 - " + room);
        }

    }

    /**
     * 退房
     */
    public void exit(int roomNo) {
        Room room = commonService(roomNo);
        if (!check(room)) {
            System.out.println("房间号码有误，请重新输入！");
        } else if (!room.isStatus()) {
            System.out.println("房间已退房不可重复操作!");
        } else {
            room.setStatus(false);
            System.out.println("感谢您的操作 - " + room);
        }
    }

    private Room commonService(int roomNo) {
        Room room = null;
        try {
            room = rooms[roomNo / 100 - 1][roomNo % 100 - 1];
        } catch (Exception e) {
//            e.printStackTrace();
        }
        return room;
    }

    private boolean check(Room room) {
        if (room == null) return false;
        return true;
    }
}
